function myready() {
	changeh(document.documentElement.scrollHeight+500);
	$(".page td img").click(function() {
		var aid = $(this).attr('aid');
		var page = $(this).attr('page');
		updatepage(aid, page)
	});
	$("#addbtn").click(function() {
		sendvalue()
	});
	$("#closebtn").click(function() {
		$(".addtb").hide()
	});
	$(".del").click(function() {
		var adminname = $(this).parent().parent().find("td:eq(0)").html();
		if (!confirm("确定要删除管理员" + adminname)) {
			return false
		}
		var aid = $(this).attr('aid');
		$.ajax({
			type: 'POST',
			url: 'caopan.php',
			data: "xtype=del&aid=" + aid,
			success: function(m) {
				if (Number(m) == 1) {
					alert("删除成功");
					$("#del" + aid).parent().parent().remove();
					window.location.href = window.location.href
				} else {
					alert("删除失败")
				}
			}
		})
	});
	$(".edit").click(function() {
		var aid = Number($(this).attr('aid'));
		$(".addtb").show('fast');
		$("#action").val('edit');
		$("#adminname").val('');
		$(".adminname").attr("aid", aid);
		$(".adminname").html($(this).parent().parent().find("td:eq(0)").html());
		if (aid == 1001) {
			$("#adminname").hide();
			$(".adminname").show()
		} else {
			$(".adminname").show();
			$("#adminname").hide()
		}
		var posi = $(this).position();
		$(".addtb").css('left', posi.left + $(this).width() - 150);
		$(".addtb").css('top', posi.top + $(this).height());
		$("#addbtn").val("修改")
	});
	$(".add").click(function() {
		$(".addtb").show('fast');
		$("#action").val('add');
		$("#adminname").val('');
		$(".adminname").html('');
		$(".adminname").hide();
		$("#adminname").show();
		var posi = $(this).position();
		$(".addtb").css('left', posi.left + $(this).width() - 150);
		$(".addtb").css('top', posi.top + $(this).height());
		$("#addbtn").val("添加")
	})
	
	
			$(".record").click(function(){
			   if($(this).val()=='记录'){							
			     var uid = $(this).attr('aid');
				 var username = $(this).attr('aname');
				 var posi= $(this).position();
				 $(".recordtb").css("left",5);
				 $(".recordtb").css("top",posi.top+$(this).height());
				 showrecord(uid,username);
				 $(".recordtb").show();
				 $(this).val("关闭记录");
			   }else{
			       $(this).val("记录");
				   $(".recordtb").hide();
			   }
			});
}

function showrecord(uid,username){

		$.ajax({
		type: 'POST',
		url: 'caopan.php',
		
		dataType:'json',
		data: 'xtype=showrecord&uid=' + uid+"&username="+username,
		cache:false,
		success: function(m) {	
            //$("#test").html(m);
		     var el = 0;
			 if(m['e']!=undefined) el=m['e'].length;
			 var ll=0;
			 if(m['l']!=undefined) ll = m['l'].length;
			 var estr = "<tr><th>修改时间</th><th>修改者</th><th>修改IP</th><th>来源</th><th>备注</th></tr>";
			var lstr = "<tr><th>登陆时间</th><th>IP</th><th>来源</th><th>备注</th></tr>";
			 for (i = 0; i < el; i++) {
				estr += "<tr>";
				estr += "<td>" + m['e'][i]['moditime'] + "</td>";
				estr += "<td>" + m['e'][i]['modiuser'] + "(" + m['e'][i]['modisonuser'] + ")</td>";
				estr += "<td>" + m['e'][i]['modiip'] + "</td>";
				estr += "<td>" + m['e'][i]['addr'] + "</td>";
				estr += "<td>" + m['e'][i]['action'] + "</td>";
				estr += "</tr>"
			}
			for (i = 0; i < ll; i++) {
				lstr += "<tr>";
				lstr += "<td>" + m['l'][i]['time'] + "</td>";
				lstr += "<td>" + m['l'][i]['ip'] + "</td>";
				lstr += "<td>" + m['l'][i]['addr'] + "</td>";
				lstr += "<td>" + m['l'][i]['ifok'] + "</td>";
				lstr += "</tr>"
			}
			 $(".recordtb .e").html("<table class='tinfo wd100'>"+estr+"</table>");
			 $(".recordtb .l").html("<table class='tinfo wd100'>"+lstr+"</table>");
			 
		}});
}
function sendvalue() {
	var action = $("#action").val();
	var adminname = $("#adminname").val();
	var aid = $(".adminname").attr('aid');
	var pass1 = $("#pass1").val();
	var pass2 = $("#pass2").val();
	if (action == 'add' & (strlen(adminname) < 5 | strlen(adminname) > 10)) {
		alert("用户名必需大于或等于5个字符,小于或等于10个字任符");
		return false
	}
	if (pass1 == '' | pass1 != pass2) {
		alert("密码不能为空，并且两次密码必需输入一样");
		return false
	}
	var sendstr = '&aid=' + aid + '&adminname=' + adminname + '&pass1=' + men_md5_password(pass1) + "&pass2=" + men_md5_password(pass2) + "&action=" + action;
	$.ajax({
		type: 'POST',
		url: 'caopan.php',
		data: 'xtype=addoredit' + sendstr,
		success: function(m) {
			$("#test").html(m);
			if (Number(m) != 1) {
				if (action == 'add') {
					alert("添加失败，请重试")
				} else {
					alert("修改失败，请重试")
				}
			} else {
				if (action == 'add') {
					alert("添加成功");
					window.location.href = window.location.href
				} else {
					alert("修改成功")
				}
				$(".addtb").hide('fast')
			}
		}
	})
}
function updatepage(aid, page) {
	$.ajax({
		type: 'POST',
		url: 'caopan.php',
		data: 'xtype=updatepage&aid=' + aid + '&page=' + page,
		success: function(m) {
			if (Number(m) == 1 | Number(m) == 0) {
				$(".page img").each(function() {
					if ($(this).attr('aid') == aid & $(this).attr('page') == page) {
						$(this).attr('src', globalpath + 'img/' + m + '.gif')
					}
				})
			}
		}
	})
}
function strlen(sString) {
	var sStr, iCount, i, strTemp;
	iCount = 0;
	sStr = sString.split("");
	for (i = 0; i < sStr.length; i++) {
		strTemp = escape(sStr[i]);
		if (strTemp.indexOf("%u", 0) == -1) {
			iCount = iCount + 1
		} else {
			iCount = iCount + 2
		}
	}
	return iCount
}